package com;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.Thread.State;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.connection.jdbconnection;

public class GetAvailability extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	
	doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		PrintWriter out=resp.getWriter();
	 String uname=req.getParameter("userName");
	 
	 jdbconnection jdbconnection=new jdbconnection();
	 int count=0;
Statement statement= jdbconnection.jdbConnection();
	               try {
					ResultSet set=statement.executeQuery("select * from register where userName='"+uname+"'");
				 while(set.next())
					 
				 {
					 count++;
					 System.out.println("hi");
				 }
				 if(count>0)
				 {
					 System.out.println("User name not available.");
					 out.println("<font color='red'>User name not available</font>");
				 }
				 else 
				 {
					 System.out.println("User name available.");
					 out.println("<font color='green'>User name  available</font>");
				 }
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	}
}
